package cst.a000tyy.broadnotifytest_000tyy;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.NotificationCompat;
import android.widget.Toast;

/**
 * Created by Neusoft on 2017/5/3.
 */

public class MyBroadNotifyReceiver extends BroadcastReceiver{
    private Context context;
    private String  str="";
    public  static NotificationManager notificationManager;
    NotificationCompat.Builder builder;
    public static int notifyID=1;


    @Override
    public void onReceive(Context context, Intent intent) {
        this.context=context;
        str=intent.getStringExtra("value1");
        Toast.makeText(context,"内容是："+str,Toast.LENGTH_SHORT).show();
        sendnotify();
    }

    private void sendnotify() {
        notificationManager=(NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        builder=new NotificationCompat.Builder(context);
        Intent notifyIntent=new Intent(context,NotificationActivity.class);
                notifyIntent.putExtra("para","通知来了");
        PendingIntent pendingIntent=PendingIntent.getActivity(context,notifyID,notifyIntent,PendingIntent.FLAG_UPDATE_CURRENT);

      //  PendingIntent contentIntent=PendingIntent.getActivity(context,0,notifyIntent,0);
        builder.setContentTitle("通知栏标题")
                .setContentText("通知栏内容")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(pendingIntent);
        notificationManager.notify(1,builder.build());
    }
}
